<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title>File create w/ BlobBuilder</title>
	</head>
	<body>
    <h3>How to use</h3>
    <p>
    Type sentences you like below box, and click "create" make text file's link
    and you can get file by clicking it. This demo site
    is based on "File API's BlobBuilder" technology, so this site does not work
    with server-side programming (only works with Javascript).
    If you want to know details about those apis please check the site below.
    <a href="http://www.w3.org/TR/2010/WD-file-writer-api-20100406/">http://www.w3.org/TR/2010/WD-file-writer-api-20100406/</a>
    </p>
    <p>
    <span style="color:red">This site will work on Chrome7, Chromium and Webkit nightly build...</span> <br>More information is available in my <a href="http://blog.livedoor.jp/kotesaki/archives/1557189.html">blog</a>(Japanese only).
    </p>
    <hr>


    <textarea id=ta></textarea><br>
    <input type="button" id=btn value="create">
		<div id=urllists></div>
    <hr>
    &copy; <a href="http://twitter.com/komasshu">komasshu</a>
		<script>
    /*
      var upload = function(blob){
        var fd = new FormData();
        fd.append("xhr2upload", blob);
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "http://somewhere/upload.php");
        xhr.send(fd);                                
        xhr.onload = function(e) {
          alert('finish uploading.');
        }
      }
      */

      document.getElementById('btn').onclick = function(){
        var text = document.getElementById('ta').value;
        var bb = new BlobBuilder();
        bb.append(text);
        var getURL = window.createBlobURL || window.createObjectURL;
        //upload(bb.getBlob());
        document.getElementById('urllists').innerHTML +=
          '<a href="'+getURL(bb.getBlob())+'" target="_blank">file</a>';
      }
		</script>
	</body>
</html>
